/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Simulation.Messages;

import Simulation.Messages.Message;

/**
 *
 * @author aking2
 */

    /*
     * Message Layout
     *  0.. 0   Simulator ID
     *  1.. 1   Service ID 
     *  2.. 2   Performance Figure ID
     *  3.. 3   Padding 
     *  4..11   Start time
     * 12..19   Finish time
     */   

public class PerformanceMessage extends Message {
    
  
    
    public PerformanceMessage(
      byte simulatorIn,
      byte serviceIn,
      byte performanceIn,
      long startTimeIn,
      long finishTimeIn) {
        
        messageID   = Simulation.Messages.Message.MessageIdEnum.IOS_PERFORMANCE_RESULT;
        messageData = new byte[MessageSize(messageID)];
        SetSimulatorId( simulatorIn );
        SetServiceId(serviceIn);
        SetPerformanceId( performanceIn );
        SetStartTime( startTimeIn );
        SetFinishTime( finishTimeIn );
    }                     
    
    public PerformanceMessage(Message msg) {
        this.messageID = msg.messageID;
        this.messageData = msg.messageData;
    }    
    
    public final void SetSimulatorId(byte s) {
        messageData[0] = s;     
    }      
    
    public final void SetServiceId(byte s) {
        messageData[1] = s;     
    }          
    
    public final void SetPerformanceId(byte s) {
        messageData[2] = s;     
    }   
    
    public final void SetStartTime(long t) {
        byte[] bytes = Simulation.Utils.ByteArrayUtils.ToByte(t);
        for(int i=0; i<8; i++)
            messageData[i+4] = bytes[i];
    }    
    
    public final void SetFinishTime(long t) {
        byte[] bytes = Simulation.Utils.ByteArrayUtils.ToByte(t);
        for(int i=0; i<8; i++)
            messageData[i+12] = bytes[i];   
    }      
    
   

    public byte GetSimulatorId() {
        return messageData[0];
    }   
    
    public byte GetServiceId() {
        return messageData[1];
    }   
    
    public byte GetPerformanceId() {
        return messageData[2];
    }     
    
    public long GetStartTime() {
        long result = 0;
        byte[] bytes = new byte[8];
        for(int i=0; i<8; i++)
            bytes[i] = messageData[i+4]; 
        result = Simulation.Utils.ByteArrayUtils.BytesToLong(bytes);
        return result;
    } 
     
    public long GetFinishTime() {
        long result = 0;
        byte[] bytes = new byte[8];
        for(int i=0; i<8; i++)
            bytes[i] = messageData[i+12]; 
        result = Simulation.Utils.ByteArrayUtils.BytesToLong(bytes);
        return result;
    }     

    // The Performance results that can be measured.
    // Don't monkey about with the values without seeing how they are used!!
    public static final byte PERFORMANCE_UNKNOWN        = 0;
    public static final byte PERFORMANCE_PROCESS_INPUTS = 1;
    public static final byte PERFORMANCE_SEND_OUTPUTS   = 2;
    public static final byte PERFORMANCE_FPS            = 3;
    public static final byte MAX_PERFORMANCE_TYPES      = 3;
   
}
